Introduction to Literate Programming - Application Assignment

IBM 6400

Author

Ricky Woznichak

Published

February 10, 2025

1 Creating a Variable

X <- "This is my first assignment"

2 Adding Text in Base R

2.1 Example from R’s help document

paste("Hello", "World", sep = " ")  
[1] "Hello World"
paste0("Hello", "World")  
[1] "HelloWorld"
paste("Number:", 1:5, sep = " ")  
[1] "Number: 1" "Number: 2" "Number: 3" "Number: 4" "Number: 5"

2.2 paste()` function, add “and I’m loving it!” to `X`

X <- paste(X, "and I'm loving it!")
X
[1] "This is my first assignment and I'm loving it!"

3 Creating and Modifying a Vector

Y <- c(2, 3, 4, 5)

3.1 Multiply by 2

Y <- Y * 2  

4 Printing Variables

X
[1] "This is my first assignment and I'm loving it!"
Y
[1]  4  6  8 10

5 Finding Maximum and Minimum Values

max(Y)
[1] 10
min(Y)
[1] 4

6 Loading ggplot2 and Viewing economics Data

library(ggplot2)
head(economics)

7 Visualizing economics Data

7.1 Variable Descriptions

  • date: Date of data collection
  • pce: Personal consumption expenditures (billions)
  • pop: Total population (thousands)
  • psavert: Personal savings rate (percentage)
  • uempmed: Median duration of unemployment (weeks)
  • unemploy: Number of unemployed persons (thousands)

7.1.1 Call-Out

Note

Let’s explore unemploy(unemployment numbers) against pop(population), as they are likely correlated.

7.1.2 It’s GGPLOT Time!

plot <- 'ggplot'(economics, aes(x = pop, y = unemploy)) +
  geom_point() +
  geom_smooth(method = "lm", color = "red", se = FALSE) +
  labs(title = "Unemployment vs Population",
       x = "Total Population (thousands)",
       y = "Number of Unemployed (thousands)")
plot
Figure 1: Unemployment vs Population

8 Replicating the Chart with Pipe Operator

economics |>
  'ggplot'(aes(x = pop, y = unemploy)) +
  geom_point(color = "red") +
  geom_smooth(method = "lm", color = "black", se = FALSE) +
  labs(title = "Unemployment vs Population",
       x = "Total Population (thousands)",
       y = "Number of Unemployed (thousands)")
Figure 2: Unemployment vs Population

9 Findings and Cross-Reference

What did we learn?

As seen in Figure 1, As the population increases, the number of unemployed individuals also increases. This suggests that unemployment scales with population growth.

10 Formatting and Documentation

I believe I have satisfied the above requirements. Thank you :)

😎